<!DOCTYPE html>
<html>
<head>
  <title>指令添加</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bootstrap4/css/bootstrap.min.css">
  <link rel="stylesheet" href="css2/style2.css"> 
  <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
  <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
  <script src="js2/my.js"></script>
</head>

<script type="text/javascript">
$(function(){
	$("#formID").validate({
        rules: {
            "commandMesg": {
                required: true
            },
            "commandName":{
                required:true
            }
        },
        messages:{
            "commandMesg":{
                required:"指令不能为空"
            },
            "commandName":{
                required:"指令名称不能为空"
            }
        },
        submitHandler:function(form){
        	$.ajax({
        		type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "saveCommandInfo" ,//url
                data: $('#formID').serialize(),
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 200) {
                        if(confirm(result.msg+'是否继续？？'))
                        {   
                        	 window.location.href = "addCommandInfo";
                        }
                        else
                        {  
                        	 window.location.href = "queryForCommandInfoList";
                        }
                    }
                    else{                	
                    	alert(result.msg);
                    }
                     
                },
                error : function() {
                    alert("异常！");
                }
            });
        },
        //自定义错误样式
        errorClass:"text-danger",
        //未通过验证,进行高亮处理或其他处理；
        highlight:function(input){
            $(input).closest(".form-group").addClass("has-error");
        },
        //通过验证,清除高亮效果或其他处理；
        unhighlight:function(input){
            $(input).closest(".form-group").removeClass("has-error");
        }
	});
});

function submitComm() {
 
	$.ajax({
        //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "saveCommandInfo" ,//url
            data: $('#formID').serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.code == 200) {
                    if(confirm(result.msg+'是否继续？？'))
                    {   
                    	
                    	 window.location.href = "addCommandInfo";
                    }
                    else
                    {  
                    	 window.location.href = "queryForCommandInfoList";
                    }
                }
                else{                	
                	alert(result.msg+'是否继续？？');
                }
                 
            },
            error : function() {
                alert("异常！");
            }
        });
 
}
</script>
<body>
<div class="header-area" id="headerArea">
   <div class="container h-100 d-flex align-items-center justify-content-between">
 
     <div class="logo-wrapper">
     <a th:href="@{/queryForCommandInfoList}"> 返回 </a>
	 </div>
     <!-- Search Form-->
     <div class="top-search-form">
      	 指令添加
     </div>
     <div  id="suhaNavbarToggler"><span></span><span></span><span></span></div>
   </div>
 </div>

<div class="container mt60">
  <form id="formID"  >
  	<input type="hidden" name="commandId" th:value="${commandInfoVO?.commandId}" /> 
    <div class="form-group">
       <div class="single-payment-method"> 
       		<img class="mb-3" src="img/bg-img/9.jpeg"   width="100%"alt="">
       </div>
    </div>
    <div class="form-group"> 
      <label class="title fl"></label>
      <label for="commandMesg" class="fl" >指令:</label>
      <input type="text" class="form-control" id="commandMesg" placeholder="请填写指令" 
      name="commandMesg"
      th:value="${commandInfoVO?.commandMesg}" >
    </div>
     <div class="form-group"> 
      <label class="title fl"></label>
      <label for="commandName" class="fl" >指令名称:</label>
      <input type="text" class="form-control" id="commandName" placeholder="请填写指令名称" 
      name="commandName"
      th:value="${commandInfoVO?.commandName}" >
    </div>
	<div class="form-group"> 
      <label class="title fl"></label>
      <label for="commandType" class="fl" >命令类型:</label>
      	<select id="commandType" name="commandType" class="form-control" placeholder="请选择命令类型" >
			<option value="1">十六进制</option>
			<option value="2">ASCII码</option> 
			<option value="3">十进制</option> 
		</select>
    </div>
	<div class="form-group"> 
      <label class="title fl"></label>
      <label for="commandGroup" class="fl" >分组菜单:</label>
      <select id="commandGroup" name="commandGroup" class="form-control"   placeholder="请选择分组菜单"   >
			<option value="1" selected>常用参数1</option>
			<option value="2">常用参数2</option> 
			<option value="3">传感器参数</option> 
			<option value="4">高级功能</option> 
			<option value="5">其他</option> 
			<option value="6">其他设置</option> 
	 </select>
    </div>
	<div class="form-group"> 
      <label class="title fl"></label>
      <label for="areaType" class="fl" >分度值类型:</label>
        <select id="areaType" name="areaType" class="form-control"   placeholder="请选择分度值类型"   >
			<option value="1" selected>数字常量最大值</option>
			<option value="2">列表选项</option> 
			<option value="3">无</option>  
	 	</select>
    </div>	 
    <div class="form-group"> 
      <label class="title fl"></label>
      <label for="commandArea" class="fl" >分度值:(【1,2】)</label>
      <input type="text" class="form-control" id="commandArea" placeholder="请填写分度值" 
	      name="commandArea"
	      th:value="${commandInfoVO?.commandArea}" >
    </div>
	<div class="form-group"> 
      <label class="title fl"></label>
      <label for="areaOption" class="fl" >分度值仪表显示:(【10%,20%】)</label>
      <input type="text" class="form-control" id="areaOption" placeholder="请填写分度值刻度" 
	      name="areaOption"
	      th:value="${commandInfoVO?.areaOption}" >
     
    </div>
<!-- 		 
     <button type="button" class="btn btn-primary btn-block" onclick="submitComm();">提交</button>
-->	
     <button type="submit" class="btn btn-primary btn-block" >提交</button>
  </form>
 
</div>

</body>
</html>
   

